﻿var EmpNo = $.getUrlParam('UserID')
console.log(EmpNo)
var passwd = 0
var a = 0
window.onload = function() {
	//---------------------
	$("#change")[0].href="changepass.html?UserID="+EmpNo
	$("#forget")[0].href="verify.html?UserID="+EmpNo
	$("#pwd-input").focus()
	$(".pwd-box").click(function() {
		$("#pwd-input").focus()
	})
	$("#btn").click(submit)
	var $input = $(".fake-box input");
	$("#pwd-input").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input.eq("" + i + "").val(pwd[i]);
		}
		$input.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 6) {

		}
	});
}

function submit(i) {
	var passport_num = $("#pwd-input").val();
	if(passport_num.length >= 6) {
		var enter = passport_num
		var date_year = new Date().getFullYear()
		var date_mon = new Date().getMonth()
		date_mon = date_mon.toString().length < 2 ? "0" + (date_mon - 1) : date_mon - 1
		var date_new = date_year + date_mon
		if(enter.length == 6) {
			var wsUrl = "http://drpapi.kukahome.com:8099/Lookfor/trans";
			enter = md5(enter)
			var data;
			data = '<?xml version="1.0" encoding="utf-8"?>';
			data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
			data = data + '<soap:Body>';
			data = data + '<GetUserSalary xmlns="http://tempuri.org/">';
			data = data + '<Page_no>1</Page_no>';
			data = data + '<Page_size>10</Page_size>';
			data = data + '<EmpNo>' + EmpNo + '</EmpNo>';
			data = data + '<Passport>' + enter + '</Passport>';
			data = data + '<yearmonth>' + date_new + '</yearmonth>';
			data = data + '</GetUserSalary>';
			data = data + '</soap:Body>';
			data = data + '</soap:Envelope>';
			var datav = {
				data:data,
				"SOAPAction": "http://tempuri.org/GetUserSalary"
			}
			var soap = datav
			$.ajax({
				"url": wsUrl,
				"type": 'POST',
				"async": false,
				"dataType": 'text',
				"data": soap,
				"success": function(data) {
					var msg = $(data).find("GetUserSalaryResult").text()
					msg = JSON.parse(msg)
					if(msg.error == 2) {
						$("#hint").html(msg.msg)
						$("#pwd-input").val("")
						$(".fake-box input").val("")
					} else if(msg.error) {
						$("#hint").html(msg.msg)
						$("#pwd-input").val("")
						$(".fake-box input").val("")
					} else {
						$("#pwd-input").val("")
						$(".fake-box input").val("")
						window.location.href = "gongzi.html?UserID="+EmpNo+"&pass="+enter
					}
				},
				"error": function(data) {
					console.log(data)
					$("#hint").html("网络出问题了")
				},
				headers: {
					"Content-Type": 'application/x-www-form-urlencoded;charset=UTF-8',
//					Accept: "XML",
//					"Content-Type": 'text/xml;charset=UTF-8',
//					"SOAPAction": "http://tempuri.org/GetUserSalary",
				}
			});
		}
	} else {
		$("#hint").html("请输入6位数完整密码")
	}
}
//--------------------------------------